﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class RssDAO
    {
        #region lay tat ca rss
        public static List<RssDTO> getAllRss()
        {
            SqlConnection connect = null;
            List<RssDTO> list = new List<RssDTO>();
            try
            {
                connect = DataProvider.Connect();
                string strCommand = "select * from rss";
                SqlCommand command = new SqlCommand(strCommand, connect);
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    RssDTO rss = new RssDTO();
                    rss.Id = reader.GetInt32(0);
                    if (!reader.IsDBNull(1))
                        rss.Url = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                        rss.Type = reader.GetInt32(2);
                    list.Add(rss);
                }
                if (list.Count == 0)
                {
                    list = null;
                }
            }
            catch (Exception ex)
            {
                list = null;
            }
            finally
            {
                if (connect != null && connect.State == System.Data.ConnectionState.Open)
                    connect.Close();
            }
            return list;
        }
        #endregion
    }
}
